import unittest
import io, sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')  # 解

def mathfunc(n1, n2):
    return n1+n2

class AutoTest(unittest.TestCase):
    def setUp(self):#每条用例执行前都要执行
        print('执行之前')

    def tearDown(self):#每条用例执行后都要执行
        print('执行之后')

    def test_pass(self):
        print('test_pass')
        result = mathfunc(1,2)
        self.assertEqual(3,result) #断言

    def test_fail(self):
        print('test_fail')
        result = mathfunc(1,0)
        self.assertEqual(1,result,'出BUG了')

    def nomath(self):
        print('nomath')

if __name__ == "__main__": #如果直接执行将执行以下代码，调用不执行以下代码
    # unittest.main()
    #构造测试集
    suit = unittest.TestSuite()
    suit.addTest(AutoTest("test_pass"))
    runner = unittest.TextTestRunner()
    runner.run(suit)#运行测试用例
